|
|
|
|
|
|
|
To begin creating the Color Button control, you need to start a new ActiveX Control project. After creating the project, set the properties of the project and the user control, as shown in Table 14.2. |
|
|
|
|
| Table 14.2 Properties of the Project and Control | | Item | Setting | | Project Name | ColorButton | | Project Description | Color Enhanced Command Button | | User control Name property | ColorBtn | | User control Public property | True |
|
|
|
|
|
|
Creating the User Interface |
|
|
|
|
|
|
|
|
In previous examples, you drew the user interface on the UserControl object by using existing controls. However, in this user-drawn control, you can create the interface entirely with code in the UserControl's event procedures. You need to place the code to draw the shape of the Color Button in the Paint event of the UserControl. The Paint event is fired whenever the container (such as a form) that holds your control is redrawn. You can also force the Paint event by issuing the Refresh method of the control. Keep in mind that your command button is really just a picture. You will be using graphics methods, such as the Line method, to draw what the user sees. For example, when a user clicks your control, you will use lines to redraw the button so that it looks like it has been pressed. For more information about graphics methods, refer to Chapter 19, "Using Visual Design Elements." |
|
|
|
|
|
|
|
|
See ''Using the Line and Shape Controls," p. 426 |
|
|
|
|
|
|
|
|
To draw a rectangular command button, you need only the Line and Print methods. In this case, the button fills the entire space of the UserControl area. The code for drawing a colored button involves three steps: |
|
|
|
|
|
|
|
|
1. Use the Line method of the UserControl object to draw a filled rectangular box the full size of the control. To create a box at the appropriate size, use the Height and Width of the control as parameters in the Line method. |
|
|
|
|
|
|
|
|
2. To simulate the "raised" state of the button, change the colors of the lines that form the rectangular box. This action involves additional calls to the Line method that draw a white line along the top and left edges of the control and a black line along the bottom and right edges of the control. These lines give the button the standard "raised" appearance. (When the button is "pressed," you reverse the appearance by swapping the white and black lines.) |
|
|
|
|
|
|
|
|
3. Using the Print method, draw a caption on the button. |
|
|
|
|
|